<?php
declare (strict_types = 1);

namespace app\admin\model\admin;

/**
 * @mixin \think\Model
 */
class AdminPermission extends BaseModel
{
    /**
     * 子权限
     */
    public function child()
    {
        return $this->hasMany('AdminPermission','pid','id');
    }

    /**
     * 获取正常状态下的菜单
     */
    public function getNormalMenuList()
    {
        $perms = self::where('status', self::NORMAL_STATE)
                ->order('sort','DESC')
                ->order('id','ASC')
                ->select();
        foreach ($perms as $p)
        {
            $permissions[$p['id']] = [
                'id'    => $p['id'],
                'pid'   => $p['pid'],
                'title' => $p['title'],
                'href'  => APP_DS_PHP.$p['href'],
                'icon'  => 'layui-icon '.$p['icon'],
                'type'  => $p['type'],
                'sort'  => $p['sort']
            ];
        }
        return $permissions;
    }
}
